class Solution(object):
    def minimumLength(self, s):
        left = 0
        right = len(s) - 1
        while left < right:
            if s[left] == s[right]:
                base = s[left]
                while left <= right:
                    if s[left] == base:
                        left += 1
                    else:
                        break
                while right >= left:
                    if s[right] == base:
                        right -= 1
                    else:
                        break
            else:
                break
        return right - left + 1
